package cn.kgc.controller;

import cn.kgc.dto.ResultInfo;
import cn.kgc.pojo.Contact;
import cn.kgc.service.ContactService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@Api(tags = "查询全部接口")
@RequestMapping("/getAll")
public class GetAllController {
    @Resource
    private ContactService contactService;
    @ApiOperation("查询全部内容，并根据当前第几页返回")
    @ApiImplicitParam(name = "pageNum",value = "当前页的页数",required = true)
    /**
     * 查询全部内容，并根据当前第几页返回
     */
    @GetMapping(value = "/getAllContact")
    public ResultInfo getAllContact(String pageNum){
        int pageNum1;
        if (pageNum==null){
            pageNum1=1;
        }else{
            pageNum1=Integer.parseInt(pageNum);
        }
        try {
            return new ResultInfo(200,"查询成功",contactService.findAllContact(pageNum1,5));
        }catch (Exception e){
            return new ResultInfo(500,"查询失败",null);

        }

    }
}
